package com.itheima.UDP.UDP接收协议;




import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ServiceDemo2 {
    public static void main(String[] args) throws IOException {
        DatagramSocket dgs = new DatagramSocket(1);
        while (true){


        byte[] bys = new byte[1024];
        DatagramPacket dgp = new DatagramPacket(bys, bys.length);

        dgs.receive(dgp);

        byte[] data = dgp.getData();
        int length = dgp.getLength();

        System.out.println(new String(data, 0, length));
        }
        //  dgs.close();
    }
}
